﻿<%@ Page Title="配货作业" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/steps/jquery.steps2.css" rel="stylesheet" />

    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/distribute/Distribute.css" rel="stylesheet" />
    <link href="../assets/css/plugins/jQuery-DataTables/css/dataTables.bootstrap.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/js/plugins/jQuery-DataTables/extensions/Select/css/select.bootstrap.min.css" rel="stylesheet" />
    <link href="../assets/js/plugins/jQuery-DataTables/extensions/Buttons/css/buttons.bootstrap.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/select2/select2.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/select2/select2-bootstrap.min.css" rel="stylesheet" />
    <style>
        .right-side {
            background-color: #808080;
        }

        #search-materialID-step3 {
            width: 600px !important;
        }

        @media (max-width:2000px) {
            #search-materialID-step3 {
                width: 800px !important;
            }
        }

        @media (max-width:1500px) {
            #search-materialID-step3 {
                width: 550px !important;
            }
        }

        @media (max-width:1170px) {
            #search-materialID-step3 {
                width: 420px !important;
            }

            /*.infoStep3 {
                width: 300px;
            }*/
        }

        @media (max-width:970px) {
            #search-materialID-step3 {
                width: 430px !important;
            }

            .infoStep3 {
                width: auto;
            }
        }

        @media (max-width:768px) {
            #input-allotted-step3 {
                width: 100% !important;
            }

            #search-materialID-step3 {
                width: 200px !important;
            }

            .infoStep3 {
                width: auto;
            }
        }

        #btn-search-step3 {
            margin-top: 5px;
        }

        #search-materialID-step3 {
            padding: 1px;
        }

        .wizard .dataTables_scrollBody { /*datatables表格 滚动框下加border*/
            border-bottom: 1px solid #e7eaec;
        }

        #tableStep21_wrapper .dataTables_scrollBody {
            /*border-right:1px solid #e7eaec;*/
        }
        /*所有表格行高缩小*/
        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            padding: 2px;
        }

        @media (max-height:550px) {
            #allotTypeBox > div {
                width: 100%;
            }
        }

        .bigerswal {
            width: 500px;
        }
        .RedText{ color: red !important;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">

            <div id="stepsController" class="smallBox" hidden>
                <h3>
                    <span class="step-icon"><i class="fa fa-user"></i></span>
                    <span class="step-title">账户信息</span>
                </h3>
                <section class=" ">

                    <h2 class=" block  text-center text-default"><i class="fa fa-hand-o-right icon-animated-hand-pointer"></i>&nbsp;欢迎使用【配货作业】，请选择配货方式</h2>
                    <div class="row m-t-lg" id="allotTypeBox">
                        <div class="col-sm-2 "></div>
                        <div class="col-sm-8 ">
                            <div class="panel panel-primary">
                                <div class="list-group">
                                    <a href="#" class="pickType list-group-item active" data-type="1">
                                        <h3 class="list-group-item-heading"><i class="fa fa-check-circle-o "></i>&nbsp;<span class="pickTypeName">按【可用库存】配货</span></h3>
                                        <p class="list-group-item-text">
                                            说明：按可用库存配货，需选择货号、配货仓库、店铺；
                                    货号可多选，配货仓库单选，并实时计算ERP系统可用库存；
                                        </p>
                                    </a>
                                    <a href="#" class="pickType list-group-item" data-type="2">
                                        <h3 class="list-group-item-heading"><i class="fa fa-circle-o"></i>&nbsp;<span class="pickTypeName">按【成品外发到货通知单】配货</span></h3>
                                        <p class="list-group-item-text">
                                            说明：按成品外发到货通知单配货，需选择ERP系统单号并查询出对应的货号；
                                    将货号按企划比例分配至虚拟仓，由虚拟仓作为配货方进行计算，货号可多选；
                                        </p>
                                    </a>
                                </div>

                            </div>
                        </div>
                        <div class="col-sm-2 "></div>
                    </div>


                    <div hidden>
                        <div class="pageControl"></div>
                    </div>
                </section>

                <h3>
                    <span class="step-icon"><i class="fa fa-credit-card"></i></span>
                    <span class="step-title">选货号</span>
                    <span class="step-info" hidden><span class="pickTypeNameTxt"></span>，请选择参与本次配货的货号，配货单号：<b class="taskBillNo"></b></span>
                </h3>
                <section>

                    <div class="filter">
                        <form class="form-inline ">

                            <div class="form-group ">
                                <label for="earch-stockID-step3">配货仓库：</label>
                                <select class="form-control" id="search-stockID-step3">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                            <div class="form-group ">
                                <label for="search-materialID-step3">货号：</label>
                                <textarea type="text" class="form-control " id="search-materialID-step3" cols="50" rows="2" placeholder='货号以","分隔'></textarea>
                            </div>
                            <button type="button" class="btn btn-default pull-right " id="btn-search-step3">查询</button>
                        </form>
                        <hr class="m-t-xs m-b-xs" style="margin: 0;" />
                        <form class="form-inline ">
                            <div class="form-group ">
                                <label for="exampleInputName2">分配比例：</label>
                                <div class="input-group">
                                    <input type="number" class="form-control " id="input-allotted-step3" size="3" style="width: 52px" />
                                    <div class="input-group-addon">%</div>
                                </div>
                            </div>
                            <div class="form-group  infoStep3" style="">
                                <span class="text-warning"><i class="fa fa-lightbulb-o"></i>&nbsp;按库存数量调整分配比例(公式说明:分配数量=库存数量*分配比例） </span>
                            </div>
                            <button type="button" class="btn btn-default pull-right" id="btn-Allotted-step3">分配</button>
                        </form>
                    </div>
                    <div class="ibox">
                        <hr class="m-t-xs m-b-xs" style="margin: 0;" />
                        <%--  <div class="ibox-title">
                        </div>--%>
                        <div class="ibox-content  ">
                            <div class="table-responsive">
                                <table id="tableStep31" class="table table-bordered" width="100%">
                                </table>
                            </div>
                        </div>
                    </div>


                </section>

                <h3>
                    <span class="step-icon"><i class="fa fa-truck"></i></span>
                    <span class="step-title">店铺配货需求</span>
                    <span class="step-info" hidden><span class="pickTypeNameTxt"></span>，请选择参与本次配货的店铺，配货单号：<b class="taskBillNo"></b>，配货仓：<b class="stockName"></b></span>
                </h3>
                <section class="">
                    <div class="ibox">
                        <%--  <div class="ibox-title">
                            <span class="text-warning"><i class="fa fa-lightbulb-o"></i>&nbsp;按库存数量调整分配比例,(公式说明:分配数量=库存数量*分配比例;留库数量=库存数量-分配数量)</span>
                        </div>--%>
                        <div class="ibox-content  ">
                            <div class="row m-n">
                                <div class="col-xs-5 no-padding">
                                    <div class="panel panel-default m-b-xxs panelLeft m-t-xs overflow-hidde">

                                        <table class="table table-bordered  text-center " id="tableStep41" style="margin-top: 0 !important; border-left: 0; border-right: 0;" width="100%">
                                        </table>
                                       
                                        <div class="panel-heading text-center form-inline no-padding">
                                         
                                                <div class="input-group input-group-sm" style="width:100%;">
                                                    <span class="input-group-addon">省:</span>
                                                    <select class="form-control" id="filter-province" style="width:100%">
                                                        <option value="">全部</option>
                                                    </select><span class="input-group-addon">市:</span>

                                                    <select class="form-control" id="filter-city"  style="width:100%">
                                                        <option value="">全部</option>
                                                    </select>
                                                    <span class="input-group-addon">
                                                        <span style="height:18px; display:block;">
                                                        <input type="checkbox" id="isOrderFlag" name="isOrderFlag" value="Y"> 企订量
                                                            </span>
                                                    </span>
                                              
                                            </div>
                                          
                                        </div>
                                        <table class="table table-bordered     text-center" id="tableStep42" style="margin-top: 0 !important; border-left: 0; border-right: 0;" width="100%">
                                        </table>
                                    </div>
                                </div>
                                <div class="col-xs-1 text-center">
                                    <%-- <button type="button" class="btn  btn-block  btn-default btn-sm" id="calcDemand">计算需求</button>--%>
                                    <div class="m-t-md addShop"><i class="fa fa-angle-right fa-3x"></i></div>
                                    <div class="addAllShop"><i class="fa fa-angle-double-right fa-3x"></i></div>
                                    <div class="m-t-md removeShop"><i class="fa fa-angle-left  fa-3x"></i></div>
                                    <div class="removeAllShop"><i class="fa fa-angle-double-left fa-3x"></i></div>
                                </div>
                                <div class="col-xs-6 no-padding  ">

                                    <div class="panel panel-default m-b-xxs panelRight m-t-xs overflow-hidde">

                                        <div class="panel-heading text-center">已选择店铺</div>
                                        <table class="table table-bordered  text-center" width="100%" id="tableStep43" style="margin-top: 0 !important; border-left: 0; border-right: 0;">
                                        </table>
                                        <div class="panel-heading text-center">店铺需求数量</div>
                                        <table class="table table-bordered   text-center" id="tableStep44" style="margin-top: 0 !important; border-left: 0; border-right: 0;" width="100%">
                                        </table>
                                    </div>


                                </div>
                            </div>

                        </div>
                    </div>
                </section>

                <h3>
                    <span class="step-icon"><i class="fa fa-newspaper-o"></i></span>
                    <span class="step-title">抢货作业</span>
                    <span class="step-info" hidden><span class="pickTypeNameTxt"></span>，店铺抢货作业，配货单号：<b class="taskBillNo"></b>，配货仓：<b class="stockName"></b></span>
                </h3>
                <section class="">
                    <div class="filter">
                        <form class="form-inline ">
                            <button type="button" class="btn btn-default" id="btn-search-shopReq">抢货</button>
                            <button type="button" class="btn btn-default" id="btn-search-shopExport">导出</button>
                            <button type="button" class="btn btn-default" id="btn-createERP">生成ERP订单</button>
                            <div class="form-group m-l-xs ">
                                <label for="input-allotted-step5">单据状态：</label>
                                <label class="radio-inline m-l-n" style="margin-left: 0; padding-left: 0;">
                                    <input type="radio" name="DocStatus" value="生效">
                                    生效
                                </label>
                                <label class="radio-inline" style="margin-left: 0; padding-left: 0;">
                                    <input type="radio" name="DocStatus" value="未生效" checked="checked">
                                    未生效
                                </label>
                            </div>
                            <div class="form-group ">
                               <%-- <label for="search-materialID-step5">操作员：</label>--%>
                                <select id="search-operator" class="form-control input-w120">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                             <div class="form-group ">
                    <%--    <label for="exampleInputName2">手工单号：</label>--%>
                        <input type="text" name="input-MaBillNo" value="" placeholder="手工单号" class="form-control input-MaBillNo" size="12"  maxlength="80" />
                    </div>
                        </form>

                    </div>
                    <div class="ibox ">
                        <div class="ibox-content  ">
                            <div class="table-responsive aaaaa">
                                <table id="tableStep51" class="table table-bordered  " width="100%">
                                </table>
                            </div>
                        </div>
                    </div>
                </section>

                <h3>
                    <span class="step-icon"><i class="fa fa-check"></i></span>
                    <span class="step-title">完成</span>
                </h3>
                <section>
                    <div class="finishContainer ">


                        <div class="block-center text-center text-success">
                            <i class="fa fa-check fa-4x"></i>
                            <div class="h2">配货作业完成!</div>
                        </div>
                    </div>
                </section>
            </div>
            <%--下面是分配虚拟仓模板--%>
            <div id="tpl" class="hide">
                <h3>
                    <span class="step-icon"><i class="fa fa-database"></i></span>
                    <span class="step-title">分配虚拟仓</span>
                    <span class="step-info" hidden>按【成品外发到货通知单】预配货，分配数量至虚拟仓，配货单号：<b class="taskBillNo"></b></span>
                </h3>
                <section class="">
                    <span class="tpl-p" hidden>分配虚拟仓</span>
                    <%--<div class="condition row"> 这个是按百分比排版
                        <form class="form-inline">
                            <div class="form-group  col-xs-6 col-sm-4  col-md-3 m-n">
                                <label class="col-sm-4 control-label m-n p-xxs text-right">商品区域</label>
                                <div class="col-sm-8  p-xxs">
                                    <select class="form-control m-n" id="search-ParentAreaID">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group  col-xs-6 col-sm-4  col-md-3  m-n">
                                <label class="col-sm-4 control-label m-n p-xxs text-right">商品区域</label>
                                <div class="col-sm-8  p-xxs">
                                    <select class="form-control m-n" id="search-ParentAreaID">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group  col-xs-6 col-sm-4  col-md-3   m-n">
                                <label class="col-sm-4 control-label m-n p-xxs text-right">商品区域</label>
                                <div class="col-sm-8  p-xxs">
                                    <select class="form-control m-n" id="search-ParentAreaID">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group  col-xs-6 col-sm-4  col-md-3   m-n">
                                <label class="col-sm-4 control-label m-n p-xxs text-right">商品区域</label>
                                <div class="col-sm-8  p-xxs">
                                    <select class="form-control m-n" id="search-ParentAreaID">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                        </form>
                    </div>--%>
                    <div class="filter">
                        <form class="form-inline ">
                            <div class="form-group ">
                                <label for="exampleInputName2">通知单号：</label>
                                <input type="text" name="input-billNo" value="AN170427KMF212-009" class="form-control input-billNo" size="22" />
                            </div>
                            单据状态：<b class="cNStateName" spanner>-</b>&nbsp;供应商名称：<b class="vendCustName" spanner>-</b>
                            <button type="button" class="btn btn-default pull-right tableStep2-save">保存</button>
                            <button type="button" class="btn btn-default pull-right tableStep2-pick">分配</button>
                            <button type="button" class="btn btn-default pull-right tableStep2-search">查询</button>
                        </form>
                    </div>
                    <div class="ibox">
                        <%-- <div class="ibox-title">
                            <span class="text-warning"><i class="fa fa-lightbulb-o"><span class="pickTypeNameTxt"></span>，请选择参与本次配货的货号</i></span>
                        </div>--%>
                        <div class="ibox-content no-padding " style="overflow: hidden">

                            <div class="row m-n">
                                <div class="col-xs-6 no-padding  " style="padding-right: 14px !important;">
                                    <table id="tableStep21" class=" table  table-bordered " width="100%" style="margin-top: 0 !important; border-left: 0; border-right: 0; border-right: 1px solid #ebebeb; border-bottom: 1px solid #ebebeb;">
                                    </table>
                                    <div class="no-padding text-center pulltool" style="position: absolute; right: -5px; top: 0;">
                                        <a class="pullRight" href="javascript:;"><i class="fa fa-arrow-circle-o-right fa-2x"></i></a>
                                        <br />
                                        <a class="pullDown" href="javascript:;"><i class="fa fa-arrow-circle-o-down fa-2x"></i></a>
                                    </div>
                                </div>
                                <%--                                <div class="col-xs-1  no-padding text-center pulltool">
                                    <a class="pullRight" href="javascript:;"><i class="fa fa-arrow-circle-o-right fa-3x"></i></a>
                                    <br />
                                    <a class="pullDown" href="javascript:;"><i class="fa fa-arrow-circle-o-down fa-3x"></i></a>
                                </div>--%>
                                <div class="col-xs-6  no-padding  " style="padding-left: 14px !important;">
                                    <table id="tableStep22" class=" table table-bordered " width="100%" style="margin-top: 0 !important;">
                                    </table>

                                </div>
                            </div>

                        </div>
                        <hr class="m-t-xs m-b-xs" style="margin: 0;" />
                        <%--   <div class="ibox-title m-t-xs" style="border-bottom: 1px solid #f5f5f6;">
                            <b>分配结果</b>
                        </div>--%>

                        <div class="ibox-content no-padding  contentStep23" style="overflow: hidden">
                            <table hidden id="tableStep23" class="table  table-bordered" width="100%" style="margin-top: 0 !important; border-left: 0; border-right: 0;">
                                <tfoot>
                                    <tr>
                                        <th></th>
                                    </tr>
                                </tfoot>
                            </table>
                            <div class="text-center h5 p-lg  no-data-23 text-muted" style=""><i class="fa fa-hand-o-right"></i>请选择货号和虚拟仓进行分配</div>
                        </div>
                    </div>


                </section>
            </div>

        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/plugins/staps/jquery.steps.min.js"></script>
    <script src="../assets/js/plugins/linq/jquery.linq.min.js"></script>


    <script src="../assets/js/plugins/numeraljs/numeral.min.js"></script>

    <script src="../assets/js/plugins/jQuery-DataTables/jquery.dataTables.min.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/dataTables.bootstrap.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/extensions/Select/js/dataTables.select.min.js"></script>
    <script src="../assets/js/plugins/jQuery-DataTables/extensions/Buttons/js/dataTables.buttons.min.js"></script>

    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script src="../assets/js/plugins/spin/spin.min.js"></script>
    <script src="../assets/js/plugins/select2/select2.full.min.js"></script>
    <script src="../assets/js/plugins/select2/i18n/zh-CN.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script>
        //$('p:textEquals("dmhai")');
        $.expr[':'].textEquals = $.expr.createPseudo(function (arg) {
            return function (elem) {
                return $(elem).text().match("^" + arg + "$");
            };
        });

        //$('p:valEquals("dmhai")');
        $.expr[':'].textEquals = $.expr.createPseudo(function (arg) {
            return function (elem) {
                return $(elem).val().match("^" + arg + "$");
            };
        });
        var dataList = [];
        $(document).ready(function () {
            var ModuleID = "";
            var startstep = 0;

            var contentHeight = 0;
            //计算容器大小
            var calcContainer = function () {
                //计算step容器高度
                contentHeight = $('.wizard').height() - $('.wizard .steps').outerHeight(true) - 42;
                $('.wizard .content').height(contentHeight);
            }
            calcContainer();
            $(window).resize(function () {
                calcContainer();
                resetBox();
            });

            //解绑事件
            $(document).off("mousewheel", 'input[type="number"]');
            //配货单号
            var TaskBillNo = "";
            var OutStockID = "";
            var StockName = "";
            //配货方式:1可用库存 2成品外发到货通知单
            var TaskType = 1;
            //任务状态: 1.未完成；2.草稿；3.ERP生效；4.未生效；-1.作废
            var TaskFlag = 99;

            if (!Y.checkNull(Y.getUrlParam("step"))) {
                ModuleID = Y.getUrlParam("ModuleID");
                startstep = parseInt(Y.getUrlParam("step"));
                TaskBillNo = Y.getUrlParam("TaskBillNo");
                OutStockID = Y.getUrlParam("OutStockID");
                StockName = Y.getUrlParam("StockName");
                TaskType = Y.getUrlParam("TaskType");
                TaskFlag = Y.getUrlParam("TaskFlag");
                $(".taskBillNo").text(TaskBillNo);
                $(".stockName").text(StockName);
            }
            //选中的货号列表
            var MaterialIDList = [];
            //分配比例
            var allottedPercent = "";
            var pickTypeName = $(".pickType h3 .pickTypeName").eq(0).text();
            $(".pickTypeNameTxt").text(pickTypeName);
            //是否分配虚拟仓
            var isInsertDCVirtualStock = false;
            //选择配货方式
            $(document).on("click", ".pickType", function () {

                var type = $(this).attr("data-type");
                TaskType = type;
                pickTypeName = $(this).find("h3 .pickTypeName").text();
                $(".pickTypeNameTxt").text(pickTypeName);
                var check = "fa-check-circle-o",
                    uncheck = "fa-circle-o";
                $(".pickType").removeClass("active").find("h3 i").removeClass(check).addClass(uncheck);
                $(this).addClass("active").find("h3 i").removeClass(uncheck).addClass(check);
                var hastpl = $(".wizard .tpl-p").length;

                if (type == 1) {
                    if (hastpl <= 0) return;
                    //分配虚拟仓已移出单独页面 20170610
                    //  $("#stepsController").steps("remove", 1);
                    // $(".wizard > .steps >  ul > li").css({ "width": "20%" });
                } else if (type == 2) {
                    if (hastpl > 0) return;
                    var titleHtml = $("#tpl h3").html();
                    //分配虚拟仓已移出单独页面 20170610
                    //var contentHtml = $("#tpl section").html();
                    //$("#stepsController").steps("insert", 1, {
                    //    title: titleHtml,
                    //    content: contentHtml
                    //});
                    //$(".wizard > .steps >  ul > li").css({ "width": "16.66%" });
                }
                //由于分配虚拟仓  是动态生成的，所以这里要手动给 tableStep23对象清空
                $("#tableStep23").hide();
                $(".no-data-23").show();
                if (tableStep23) tableStep23 = undefined;
            });
           
            //表格滚动高度 等参数
            var tableStep21, tableStep22, tableStep23, tableStep31, tableStep41, tableStep42, tableStep43, tableStep44, tableStep51;
            var paddingBottom = 5;
            var tableHeadHight = 28, tableHeadMargin = 6;//这个是datatables表头高度 表头
            var tfootHeight = 25; //tfoot 高
            var tableStep21Height = 250, tableStep22Height = 250, tableStep23Height = 250;
            var tableStep31Height = 250;
            var tableStep41Height = 250, tableStep42Height = 250, tableStep43Height = 250, tableStep44Height = 250;
            var tableStep51Height = 250;
            var wizard = $("#stepsController").steps({
                headerTag: "h3",
                bodyTag: "section",
                titleTemplate: "#title#",
                //enableKeyNavigation: false,
                enableAllSteps: false,
                startIndex: startstep,
                onInit: function () {
                    calcContainer();
                    resetBox();
                    initTable();
                    if (startstep == 3) {
                        $(".pickType[data-type='" + TaskType + "']").trigger("click");
                        //给上一步添加灰色 不能点上一步
                        $(".actions").find("a[href='#previous']").parent("li").addClass("disabled");
                        //禁用点击步骤
                        $(this).find(".steps li").slice(0, startstep).addClass("disabled");

                    }
                    //企订量
                    $("#isOrderFlag").iCheck({ checkboxClass: "icheckbox_square-green" });
                },
                labels: {
                    next: "下一步 <i class='fa fa-arrow-right'></i>",
                    previous: "<i class='fa fa-arrow-left'></i> 上一步",
                    finish: "<i class='fa fa-check'></i> 完成"
                },
                onStepChanging: function (event, currentIndex, newIndex) {

                    var hastpl = $(".wizard .tpl-p").length;//是否选择分配虚拟仓

                    var direction = currentIndex > newIndex ? "prev" : "next";

                    if (direction == "next") {

                        if (hastpl && currentIndex == 1) {
                            if (!isInsertDCVirtualStock)//如果没分配不能下一步
                            {
                                //swal("请分配虚拟仓！");
                                //return false;

                            }

                        } else if (((hastpl && currentIndex == 2) || (!hastpl && currentIndex == 1))) {//选货号 模块 下一步
                            if (MaterialIDList.length == 0) //如果没有选中货号 不能到下一步
                            {
                                swal("请选择货号！");
                                return false;
                            }

                            if (Y.checkNull(allottedPercent)) {
                                swal("分配比例不能为空！");
                                return;
                            }
                        } else if (((hastpl && currentIndex == 3) || (!hastpl && currentIndex == 2))) //店铺配货需求 模块 下一步
                        {


                            if (!tableStep31 || tableStep31.data().length == 0 || step4Data.length == 0 || MaterialIDList.length == 0) {
                                swal("请选择店铺！");
                                return false;
                            }
                        }


                    }
                    //抢货作业 从我的配货打开的禁用上一步按钮
                    if (startstep == 3 && currentIndex == 3 && direction == "prev") {
                        return false;
                    }
                    //完成后不能再上一步
                    if (direction == "prev" && currentIndex == 4) {

                        return false;
                    }

                    return true;
                },
                onStepChanged: function (event, currentIndex, priorIndex) {

                    //禁用点击步骤
                    if (currentIndex > priorIndex)
                        $(this).find(".steps li").slice(0, currentIndex).addClass("disabled")._aria("disabled", "true");
                    else {
                        $(this).find(".steps li").eq(priorIndex).addClass("disabled").removeClass("done")._aria("disabled", "true");
                    }

                    //获取content里面section 高
                    var sectionHeight = contentHeight - $("h3.title.current").outerHeight(true);
                    var curStepObj = wizard.steps("getCurrentStep");
                    // $(curStepObj.content).find("input").text("234")

                    var iboxHeight = 0;//头部
                    $("section.current").find(".ibox .ibox-title").each(function () {
                        iboxHeight += $(this).outerHeight(true);

                    });

                    //console.log(sectionHeight)
                    //console.log(iboxHeight)
                    //console.log(panelHeading)
                    //还没使用的高度
                    var curStepAllTableHeight = sectionHeight - $("section .filter").outerHeight(true) - iboxHeight;

                    if (currentIndex == 0) {

                    } else if (currentIndex == 1) {
                        //var _allotType = 1;
                        //if (hastpl) _allotType = 2;
                        Y.API2('PickingOperations', 'GetTaskBillNo', {
                            AllotType: TaskType
                        }, function (data) {

                            if (data.Success == false) {
                                swal(data.Message, '', 'error');
                            }
                            else {
                                TaskBillNo = data.TaskBillNo;
                                $(".taskBillNo").text(TaskBillNo);
                            }
                        });
                    }
                    resetBox();
                    initTable();

                },
                onFinishing: function () {
                    layer.msg('跳转……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                    location.href = window.location.pathname + "?ModuleID=" + ModuleID;
                }
            });

            //重置表格高度
            function resetBox() {
                var currentIndex = $("#stepsController").steps("getCurrentIndex");
                //获取content里面section 高
                var sectionHeight = contentHeight - $("h3.title.current").outerHeight(true);
                var curStepObj = $("#stepsController").steps("getCurrentStep");
                var iboxHeight = 0;//头部
                $("section.current").find(".ibox .ibox-title").each(function () {
                    iboxHeight += $(this).outerHeight(true);
                });

                //还没使用的高度
                var curStepAllTableHeight = sectionHeight - $("section.current .filter").outerHeight(true) - iboxHeight;

                var hastpl = $(".wizard .tpl-p").length;//是否选择分配虚拟仓
                //if (hastpl && currentIndex == 1) {   //分配虚拟仓
                //    //平分
                //    tableStep21Height = tableStep22Height = tableStep23Height = curStepAllTableHeight / 2;

                //    // console.log(tableStep21Height)
                //    $(".pulltool").outerHeight(tableStep21Height);
                //    $(".ibox-content>.row>div").outerHeight(tableStep21Height - 1);
                //    $(".contentStep23").outerHeight(tableStep23Height);
                //    //console.log(tableStep21Height)
                //    tableStep21Height -= tableHeadHight;
                //    tableStep22Height -= tableHeadHight;
                //    tableStep23Height = tableStep23Height - tableHeadHight - tfootHeight;

                //    if (tableStep21) {
                //        $(tableStep21.table().container()).find(".dataTables_scrollBody").height(tableStep21Height);
                //    }
                //    if (tableStep22) {
                //        $(tableStep22.table().container()).find(".dataTables_scrollBody").height(tableStep22Height);
                //    }
                //    if (tableStep23) {
                //        $(tableStep23.table().container()).find(".dataTables_scrollBody").height(tableStep23Height);
                //    }
                //    ////console.log(tableStep21Height)

                //} else
                if ((hastpl && currentIndex == 1) || (!hastpl && currentIndex == 1)) {//选货号 模块

                    tableStep31Height = curStepAllTableHeight - tableHeadHight - paddingBottom - tableHeadMargin;

                } else if ((hastpl && currentIndex == 2) || (!hastpl && currentIndex == 2)) {//店铺配货需求 模块
                    //绑定
                    var panelHeading = 0; //panel头部
                    // $("section.current").find(".panel .panel-heading").each(function () {
                    panelHeading = $("section.current").find(".panel .panel-heading").outerHeight(true);
                    var marginTop = 8;//一些框 的外边框 + 边框
                    // })
                    //console.log(panelHeading)
                    //console.log(tableHeadHight * 2)
                    $("section.current").find(".panel").outerHeight(curStepAllTableHeight - paddingBottom, true);
                    tableStep41Height = tableStep42Height = (curStepAllTableHeight - panelHeading - paddingBottom - (tableHeadHight - 4) * 2 - marginTop) / 2;
                    tableStep44Height = 24;//固定的
                    tableStep43Height = curStepAllTableHeight - panelHeading * 2 - paddingBottom - (tableHeadHight - 6) * 2 - tableStep44Height - marginTop;//tableHeadHight 在panel里面实际只有24 非28 要减4-6像素
                    if (tableStep41) {
                        $(tableStep41.table().container()).find(".dataTables_scrollBody").height(tableStep41Height);
                    }
                    if (tableStep42) {
                        $(tableStep42.table().container()).find(".dataTables_scrollBody").height(tableStep42Height);
                    }
                    if (tableStep43) {
                        $(tableStep43.table().container()).find(".dataTables_scrollBody").height(tableStep43Height);
                    }

                } else if ((hastpl && currentIndex == 3) || (!hastpl && currentIndex == 3)) {//店铺配货需求 模块
                    tableStep51Height = curStepAllTableHeight - tableHeadHight - tableHeadMargin - paddingBottom;
                }

            }
            function initTable() {
                var hastpl = $(".wizard .tpl-p").length;//是否选择分配虚拟仓
                var currentIndex = $("#stepsController").steps("getCurrentIndex");
                if (hastpl && currentIndex == 1) {   //分配虚拟仓

                    //if (tableStep21) tableStep21.destroy()
                    //loadTableStep21(1);
                    //if (tableStep22) tableStep22.destroy()
                    //loadTableStep22();
                    //if (tableStep23) {

                    //    clearTable23();

                    //    loadTableStep23(1);
                    //}

                } else if ((hastpl && currentIndex == 1) || (!hastpl && currentIndex == 1)) {//选货号 模块
                    //绑定
                    if ($("#search-stockID-step3 option").length <= 1) {
                        $("#search-stockID-step3").html('<option value="">请选择</option>');
                        commonUtil.bindOdsErpBasStocks3({}, ['#search-stockID-step3']); //配货仓库
                    }
                    MaterialIDList = [];
                    // tableStep31Height = curStepAllTableHeight - tableHeadHight - paddingBottom - tableHeadMargin;
                    if (tableStep31) {
                        tableStep31.clear().draw();
                    }

                } else if ((hastpl && currentIndex == 2) || (!hastpl && currentIndex == 2)) {//店铺配货需求 模块

                    
                    //绑定
                    if (tableStep41) tableStep41.destroy();
                    loadTableStep41();
                    if (tableStep42) tableStep42.destroy();
                    loadTableStep42(1);

                    if (tableStep43) tableStep43.destroy();
                    loadTableStep43(1);

                    if (tableStep44) {
                        tableStep44.clear().draw();
                    }

                } else if ((hastpl && currentIndex == 3) || (!hastpl && currentIndex == 3))//抢货作业 模块
                {


                    $("input[name='DocStatus']").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green" });
                    Y.API2('PickingOperations', 'GetOperator', {}, function (data) {
                        var newdata = $.map(data, function (obj) {
                            obj.id = obj.UserID;
                            obj.text = obj.UserName;
                            return obj;
                        });
                        $("#search-operator").select2({
                            language: "zh-CN",
                            theme: "bootstrap",
                            placeholder: "选择操作员",
                            data: newdata
                        });
                        //选中当前用户
                        var UserInfo = JSON.parse(window.sessionStorage.getItem('login-info'));
                        if (!Y.checkNull(UserInfo) && !Y.checkNull(UserInfo.NickName)) {
                            // UserInfo.NickName = "xxx";
                            $("#search-operator option:contains('" + UserInfo.NickName + "')").map(function () {
                                if ($(this).text() == UserInfo.NickName) {
                                    $(this).prop("selected", true);
                                    $("#search-operator").trigger('change');
                                }
                            });

                        }
                    });
                    if (TaskType == 2) { //单据状态  不可改变
                        $("input[name='DocStatus'][value='生效']").iCheck('disable');
                    }
                    if (tableStep31 && tableStep31.data().length > 0 && step4Data.length > 0 && MaterialIDList.length > 0) {
                        var _shopList = [];
                        $.each(step4Data, function (i, obj) {
                            _shopList = $.Enumerable.From(obj.Data).Where(function (x) { return x.Selected; }).Union(_shopList).ToArray();
                        });

                        //筛选传入参数
                        var paramShopList = [];
                        var ch = false;
                        $.each(_shopList, function (p, obj) {
                            if (paramShopList.length > 0) {
                               
                                $.each(paramShopList, function (q, item) {
                                    if ((obj.ShopID + obj.MaterialID) == (item.ShopID + item.MaterialID)) {
                                        ch = true;
                                        return;
                                    }
                                    else {
                                        ch = false;
                                    }
                                });
                                if(!ch)
                                {
                                    var param = {
                                        ShopID: obj.ShopID,
                                        MaterialID: obj.MaterialID,
                                    };
                                    paramShopList.push(param);
                                }
                            }
                            else {
                                var param = {
                                    ShopID: obj.ShopID,
                                    MaterialID: obj.MaterialID
                                };
                                paramShopList.push(param);
                            }
                        });
                        //清空对象所占内存
                        _shopList = [];

                        layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                        // console.log(MaterialIDList)
                        // console.log(tableStep31.data().toArray())
                        //筛选出只有选中的 货号
                        var _StockList = $.Enumerable.From(tableStep31.data().toArray()).Where(function (x) {
                            return $.Enumerable.From(MaterialIDList).Contains(x.MaterialID, "$.MaterialID");
                            
                        }).ToArray();

                        var paramStockList = [];
                        $.each(_StockList, function (p, obj) {
                            var param = {
                                //CompanyID: obj.CompanyID, //移到外面
                                //StockID: obj.StockID, //值和OutStockID相等取消内部的值
                                MaterialID: obj.MaterialID,
                                SizeID: obj.SizeID,
                                TotalQty: obj.TotalQty,
                                Percentage: obj.Percentage,
                                AllottedNum: obj.AllottedNum
                            }
                            paramStockList.push(param);
                        });
                        //获取公司代码
                        var CompanyID = "";
                        if (_StockList != null && _StockList.length > 0) {
                            CompanyID = _StockList[0].CompanyID;
                        }
                        //清空对象所占内存
                        _StockList = [];
                        

                        //处理完才能下一步
                        Y.API2('PickingOperations', 'UpdateShopSort', {
                                TaskBillNo: TaskBillNo,
                                TaskType: TaskType,
                                CompanyID: CompanyID,
                                OutStockID: OutStockID,
                                StockList: paramStockList,
                                ShopList: paramShopList
                            }
                            , function (data) {
                                layer.closeAll('dialog');
                                if (data.Success == false) {
                                    $("#stepsController").steps("previous");
                                    swal(data.Message, '', 'error');

                                }
                                else {
                             
                                    if (tableStep51) tableStep51.destroy();
                                    loadTableStep51({ TaskBillNo: TaskBillNo, OutStockID: OutStockID, Type: 1 });
                                }

                          
                            });
                    } else {

                        if (tableStep51) tableStep51.destroy();
                        loadTableStep51({ TaskBillNo: TaskBillNo, OutStockID: OutStockID, Type: 1 });
                    }



                } else if ((hastpl && currentIndex == 4) || (!hastpl && currentIndex == 4)) {
                    //给上一步添加灰色 不能点上一步
                    $(".actions").find("a[href='#previous']").parent("li").addClass("disabled");
                    //禁用点击步骤
                    $(this).find(".steps li").slice(0, startstep).addClass("disabled");
                }
            }

            // //格式化number input
            inputControl.init({
                els: ['#input-allotted-step3'],
                inputEvent: "blur",
                min: 0,
                max: 100, isNum: true
            })

            //事件
            //保存 分配虚拟仓
            $(document).on("click", ".tableStep2-save", function () {
                if ($(tableStep23.footer()).find(".text-danger").length > 0)//不能保存
                {
                    swal("分配数量不对！", '', 'warning');
                    return;
                }
                var insertDCVirtualStockModel = [];
                //数据集转换  列转行
                if (tableStep23.data()) {
                    tableStep23.data().each(function (row, i) {
                        // console.log(tableStep23.row(i).data());
                        tableStep23.columns().data().each(function (col, j) {

                            if ($.isNumeric(tableStep23.cell(0, j).data()))//判断是否数字 排除 虚拟仓和货号，留下尺码
                            {

                                var _tempRow = {};


                                _tempRow.CompanyID = row.CompanyID;
                                _tempRow.SourceBillNo = tableStep21.data()[0].SourceBillNo;
                                _tempRow.StockID = row.StockID;
                                _tempRow.MaterialID = row.MaterialID;
                                _tempRow.SizeID = tableStep23.row(i).data()["SizeID" + tableStep23.column(j).dataSrc()];
                                _tempRow.TotalQty = tableStep23.cell(i, j).data();
                                insertDCVirtualStockModel.push(_tempRow);
                            }
                        });
                    });

                    layer.msg('正在保存……', { icon: 16, shade: 0.01, time: 0, maxWidth: 200 });
                    Y.API2('PickingOperations', 'InsertDCVirtualStock', {
                        list: insertDCVirtualStockModel
                    }, function (json) {
                        layer.closeAll('dialog');
                        if (json.Success == false) {
                            swal(data.Message, '', 'error');
                        }
                        else {
                            //已经分配可以下一步
                            isInsertDCVirtualStock = true;
                            swal('保存成功', '', 'success');
                        }
                    });

                }

            });
            //分配 分配虚拟仓
            $(document).on("click", ".tableStep2-pick", function () {
                var materialID = tableStep21.$(".checkItem:checked").val();
                // materialID = "1152C5210250101";//测试的

                var stock = [];
                tableStep22.$(".checkItem:checked").each(function () {
                    stock.push({ StockID: $(this).val(), StockName: $(this).attr("data-text") });
                });
                //  console.log(stock)

                if (Y.checkNull(stock)) {
                    swal("请选择虚拟仓！");
                    return;
                }
                if (Y.checkNull(materialID)) {
                    swal("请选择货号！");
                    return;
                }

                //var array1 = [13,413,5];
                //var array2 = [13,14,53,6];

                //var aa= $.Enumerable.From(array1)
                // .Join(array2, function (x) { console.log("1"); console.log(x); return x + 1; }, function (x) { console.log("2"); console.log(x); return x; }, function (inner,outer) {

                //     return {inner:inner,outer:outer};
                // });
                // var aa= $.Enumerable.From(array1)
                //.Concat(array2);
                // console.log(aa.ToArray());
                //  return false;

                Y.API2('PickingOperations', 'GetFirstAllotList', { StockID: $.Enumerable.From(stock).Select("$.StockID").ToString(","), MaterialID: materialID }, function (data) {
                    var tmep = [];
                    var dataNew = $.Enumerable.From(tableStep21.data()).Where(function (x) { return x.MaterialID == materialID; }).Join(stock, "", "", function (inner, outer) {
                        outer.TotalQty = 0;
                        var n = $.extend({}, inner, outer);
                        return n;
                    }, function () { return true; }).ToArray();

                    if (data.length > 0) {
                        if (tableStep23) {
                            clearTable23();
                        }
                        $.each(data, function (i, obj) {
                            $.Enumerable.From(dataNew).Where(function (x) { return x.CompanyID == obj.CompanyID && x.MaterialID == obj.MaterialID && x.SizeID == obj.SizeID && x.StockID == obj.StockID }).ForEach(function (x) {
                                //合并
                                $.extend(x, obj);
                            });
                        });

                        loadTableStep23(1, dataNew);


                    }
                    else {

                        //  { CompanyID: "KM", SourceBillNo: tmep.SoourceBillNo, StockID: "", StockName: "", MaterialID: materialID, SizeID: "M1", SizeName: "M", TotalQty: tmep.TotalQty }
                        //   ];
                        // $("stockID")

                        //console.log(dataNew)

                        if (tableStep23) {
                            clearTable23();

                        }
                        loadTableStep23(1, dataNew);
                    }

                });

            });
            //查询 分配虚拟仓
            $(document).on("click", ".tableStep2-search", function () {

                var billNo = $("input[name='input-billNo']").val();
                if (Y.checkNull(billNo)) {
                    swal("通知单号不能为空！");
                    return;
                }
                var spinner = new Spinner({ scale: 0.4 }).spin();
                $(".billNo[spanner],.cNStateName[spanner],.vendCustName[spanner]").html(spinner.el);
                if (tableStep21) tableStep21.destroy();

                loadTableStep21({ BillNo: billNo });

            });
            //查询 选货号 

            $(document).on("click", "#btn-search-step3", function () {

                var stockID = $("#search-stockID-step3").val();
                OutStockID = stockID;
                var materialID = $("#search-materialID-step3").val();
                if (Y.checkNull(stockID)) {
                    swal("请选择配货仓库！");
                    return;
                }
                if (Y.checkNull(materialID)) {
                    swal("货号不能为空！");
                    return;
                }

                if (tableStep31) tableStep31.destroy();
                ///清空分配比例
                allottedPercent = "";
                loadTableStep31({ AllotType: TaskType, StockID: stockID, MaterialID: materialID });
                $(".stockName").text($("#search-stockID-step3 option:selected").text());
            });
            //分配 选货号
            $(document).on("click", "#btn-Allotted-step3", function () {
                allottedPercent = $("#input-allotted-step3").val();
                if (Y.checkNull(allottedPercent)) {
                    swal("分配比例不能为空！");
                    return;
                }
                if (!tableStep31 || tableStep31.data().length == 0) {
                    swal("无数据分配！");
                    return;
                }
                calcAllotted(allottedPercent);
            });

            //选择店铺 添加、删除 操作事件  店铺配货需求  .addShop,.removeShop,.addAllShop,.removeAllShop
            //添加 选中
            $(".addShop").on("click", function (event) {
                var e = window.event || event;
                if (tableStep42 && tableStep42.data().length > 0) {
                    var selectRowsObj = tableStep42.rows({ selected: true });
                    if (selectRowsObj.count() > 0) {
                        dataProcessStep4(selectRowsObj, "add");
                        tableStep43.rows.add(selectRowsObj.data()).draw();
                        selectRowsObj.remove().draw();
                    }
                }
            });
            //删除 选中
            $(".removeShop").on("click", function (event) {
                var e = window.event || event;
                if (tableStep43 && tableStep43.data().length > 0) {
                    var selectRowsObj = tableStep43.rows({ selected: true });
                    if (selectRowsObj.count() > 0) {
                        dataProcessStep4(selectRowsObj, "del");
                        tableStep42.rows.add(selectRowsObj.data()).draw();
                        selectRowsObj.remove().draw();
                        if (tableStep44) {
                            tableStep44.clear().draw();
                            //   tableStep44.destroy();
                            tableStep44.destroy();
                            $('#tableStep44').empty();
                            tableStep44 = undefined;
                        }
                        filterTableStep42();
                    }
                }
            });
            //添加 全部
            $(".addAllShop").on("click", function () {
                if (tableStep42 && tableStep42.data().length > 0) {
                    var selectRowsObj = tableStep42.rows();
                    if (selectRowsObj.count() > 0) {
                        dataProcessStep4(selectRowsObj, "add");
                        tableStep43.rows.add(selectRowsObj.data()).draw();
                        selectRowsObj.remove().draw();
                    }
                }
            });
            //删除 全部
            $(".removeAllShop").on("click", function () {
                if (tableStep43 && tableStep43.data().length > 0) {
                    var selectRowsObj = tableStep43.rows();
                    if (selectRowsObj.count() > 0) {
                        dataProcessStep4(selectRowsObj, "del");
                        tableStep42.rows.add(selectRowsObj.data()).draw();
                        selectRowsObj.remove().draw();
                        if (tableStep44) {
                            tableStep44.clear().draw();
                            //tableStep44.destroy();

                            tableStep44.destroy();
                            $('#tableStep44').empty();
                            tableStep44 = undefined;

                        }
                        filterTableStep42();
                    }
                }
            });

            // 店铺过虑 省市 change 事件
            // 企订量 change 事件
            $("#isOrderFlag").on("ifChanged", function () {

                filterTableStep42();
            });
            // 市 change 事件
            $("#filter-city").on("change", function () {
                filterTableStep42();
            });
            // 省 change 事件
            $("#filter-province").on("change", function () {
                //更换市
                bindShopCity();
                filterTableStep42();

            });


            //店铺配货需求 计算需求
            //$("#calcDemand").on("click", function () {
            //    //QtySum
            //    // tableStep43.column("QtySum:name").order("desc").draw();
            //    tableStep43.column("QtySum:name")
            //    tableStep43.rows().data().each(function (row, index) {
            //        tableStep43.cell(index, "SortNum:name").data(index + 1);
            //    });
            //    tableStep43.column("SortNum:name").order("desc").draw();
            //    tableStep43.draw();

            //});
            //抢货作业
            $("#btn-search-shopReq").on("click", function () {
                //判断 并禁用 抢货
                if (TaskFlag == 3 || TaskFlag == 4 || TaskFlag == -1 || TaskFlag == 0) {
                    swal("此任务单号已生成ERP单据！", "", "warning");
                    return;
                }

                //$(this).attr("disabled", true);

                layer.msg('疯狂抢货中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                var param = {
                    "Page": 1,
                    "Size": 100,
                    "TaskBillNo": TaskBillNo,
                    "OutStockID": OutStockID,
                    "Type": 2
                };
                var url = "/api.ashx?c=PickingOperations&a=GetShopReqDetail" + "&t=" + Math.random();
                $.ajax({
                    type: "post",
                    url: url,
                    data: param,
                    dataType: "json",
                    success: function(result) {

                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //$("#btn-search-shopReq").removeAttr("disabled");
                        if (tableStep51) {
                            tableStep51.ajax.reload();
                        } else {
                            loadTableStep51({ TaskBillNo: TaskBillNo, OutStockID: OutStockID, Type: 1 });
                        }
                        layer.closeAll('dialog');
                    }
                });
            });
            //导出
            $("#btn-search-shopExport").on("click", function () {
                //判断 是否 导出
                // if (TaskFlag == 3 || TaskFlag == 4 || TaskFlag == 2 || TaskFlag == 0) {

                var conditionsArr = [];
                conditionsArr.push({ column: "SRD.TaskBillNo ", value: TaskBillNo, operator: "=", connector: "and" });
                conditionsArr.push({ column: "SRD.OutStockID  ", value: OutStockID, operator: "=", connector: "and" });
                conditionsArr = JSON.stringify(conditionsArr);
                var tempParam = {};
                tempParam.filename = "店铺抢货结果";
                tempParam.filetype = "PICKINGOPERATIONS";
                tempParam.conditions = encodeURIComponent(conditionsArr);
                var t = $.Export(tempParam);

                //} else {
                //    swal("请先抢货！", "", "warning");
                //    return;
                //}


            });



            //生成ERP订单
            $("#btn-createERP").on("click", function () {
                var _billstatus = $("input[name='DocStatus']:checked").val();
                var _userID = $("#search-operator").val();
                if (Y.checkNull(_userID)) {
                    swal("操作员不能为空！", "", "warning");
                    return;
                }
                var maBillNo = $("input[name='input-MaBillNo']").val();

                if ($('#tableStep51 .checkItem:checked').length == 0) {
                    swal("请勾选要生成的店铺！", "", "warning");
                    return;
                }

                var shopIdArr = [];
                $('#tableStep51 .checkItem:checked').each(function() {
                    var tr = $(this).parents('tr');
                    shopIdArr.push($(this).val());
                });


                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                //根据任务单号生成ERP到店铺的单据API
                Y.API2('PickingOperations', 'GetErpShopOrder',
                {
                    TaskBillNo: TaskBillNo,
                    Billstatus: _billstatus,
                    UserID: _userID,
                    TaskType: TaskType,
                    MaBillNo: maBillNo,
                    List: dataList
                }, function (data) {
                    layer.closeAll('dialog');
                    if (!Y.checkNull(data)) {
                        var _list = "";

                        switch (data.RetVal) {
                        case -1:
                        case 1:
                        case 5:
                        case 6:
                            swal({ title: "<span style='font-size:16px'>" + data.Message + "</span>", type: "error", html: true });

                            break;
                        case 0:
                        case 4:
                            if (data.List.length <= 5) {//如果只有5个以内用列表
                                $.each(data.List, function (i, obj) {
                                    _list += '<li class="list-group-item">' + obj.BillNo + '</li>';
                                });
                                swal({ title: "<span style='font-size:16px'>" + data.Message + "，单号如下:</span>", text: '<ul class="list-group">' + _list + '</ul>', type: "success", html: true, customClass: "bigerswal" });
                            } else {
                                _list += '<thead><tr><th class="text-center">单号<th class="text-center">单号</th></tr></thead>';
                                _list += "<tbody>";
                                $.each(data.List, function (i, obj) {
                                    if ((i + 1) % 2 == 0) return true;
                                    _list += '<tr><td>' + data.List[i].BillNo + '</td><td>' + (Y.checkNull(data.List[i + 1]) ? "" : data.List[i + 1].BillNo) + '</td></tr>';
                                });
                                _list += "</tbody>";
                                // console.log(_list)
                                swal({ title: "<span style='font-size:16px'>" + data.Message + "，单号如下:</span>", text: '<table id="ErpRS" width="100%" class="table table-bordered table-responsive text-center">' + _list + '</table>', type: "success", html: true, customClass: "bigerswal" });
                            }
                            TaskFlag = data.RetVal;
                            break;
                        case -2:
                            _list += '<thead><tr><th class="text-center">仓库</th><th class="text-center">货号</th><th class="text-center">尺码</th><th class="text-center">需求数量</th><th class="text-center">可用库存</th><th class="text-center">差异数量</th></tr></thead>';
                            _list += "<tbody>";
                            $.each(data.Data, function (i, obj) {
                                _list += '<tr><td>' + obj.StockName + '</td><td>' + obj.MaterialID + '</td><td>' + obj.SizeName + '</td><td>' + obj.Qty + '</td><td>' + obj.CanQty + '</td><td>' + obj.DiffQty + '</td></tr>';
                            });
                            _list += "</tbody>";
                            swal({ title: "<span style='font-size:16px'>" + data.Message + "，单号如下:</span>", text: '<table id="ErpRS" width="100%" class="table table-bordered table-responsive text-center">' + _list + '</table>', type: "success", html: true, customClass: "bigerswal" });
                            break;
                        }
                        var opts = {
                            pageLength: 10,
                            language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, ordering: false, lengthChange: false,
                            drawCallback: function () {
                                $(".bigerswal").css("margin-top", (-$(".bigerswal").outerHeight() / 2) + "px");
                            }
                        };

                        $('#ErpRS').dataTable(opts);



                    } else {
                        swal("类型为空！");
                    }
                });
            });



            //数据
            //#region 数据

            //分配虚拟仓
            function loadTableStep21(data) {
                var opts = {
                    retrieve: true,
                    scrollY: tableStep21Height,

                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, paging: false, info: false, searching: false, ordering: false, lengthChange: false, processing: true,
                    drawCallback: function (setting) {
                        var api = this.api();
                        if (api.rows().data().length > 0) {
                            $(".cNStateName").html(api.rows().data()[0].CNStateName);
                            $(".vendCustName").html(api.rows().data()[0].VendCustName);
                        } else {
                            $(".cNStateName").html("-");
                            $(".vendCustName").html("-");
                        }

                        tableStep21.$("input.checkItem").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        tableStep21.$("input.checkItem").on("ifChecked", function () {
                            var materialID = tableStep21.$(".checkItem:checked").val();
                            var billNo = $("input[name='input-billNo']").val();
                            //根据货号获取店铺配货需求量数据列表API
                            Y.API2('PickingOperations', 'GetDCVirtualStock', { BillNo: billNo, MaterialID: materialID }, function (data) {
                                tableStep22.$("input.checkItem").iCheck('uncheck');
                                if (data.length > 0) {

                                    if (tableStep23) {
                                        clearTable23();
                                    }
                                    loadTableStep23(1, data);
                                    var arr = $.Enumerable.From(data).GroupBy("{StockID:$.StockID, StockName:$.StockName}", null, "$", function (x) {
                                        var _arr = [];
                                        for (var i in x) {
                                            _arr.push(x[i]);
                                        }

                                        return _arr.join("-");
                                    }).ForEach(function (x) {
                                        //选中虚拟仓
                                        tableStep22.$("input.checkItem").filter("[value='" + x.StockID + "']").iCheck('check');
                                    });
                                    //已经分配过可以下一步
                                    isInsertDCVirtualStock = true;
                                }
                                else {
                                    if (tableStep23) {
                                        clearTable23();
                                        loadTableStep23(1);
                                    }
                                }

                            });
                        });
                        //高度

                        $(tableStep21.table().node()).height("100%");
                        $(tableStep21.table().node()).height($(tableStep21.table().node()).height() - 1);//多一像素 下边框

                        //   isInsertDCVirtualStock

                    },
                    createdRow: function (row, data, dataIndex) {
                        if ($(row).find("td:first[data-groupstart]").length > 0) {//给分组加粗线
                            $(row).addClass("groupRow");
                        }
                    },
                    columnDefs: [
                        {//==============================================分组分组分组分组分组分组分组分组分组分组分组=================================================================================
                            "targets": [1, 2],//要合并的字段
                            "searchable": false,
                            createdCell: function (td, cellData, rowData, row, col) {

                                var gcol = [{ colName: 2, group: 1, baseGroup: 0 }];//要合并的组的条件，colName为对应的字段index，group：分组（1，2，3...） baseGroup:（父id）必须存在targets 中
                                $(tableStep21.cell(row, col).nodes()).addClass("groupbyColumn-" + row + " groupbyColumn-" + row + "-" + col);

                                var condition = false;
                                if (row != 0) {
                                    var g = $.Enumerable.From(gcol).GroupBy("$.group", "", function (key, e) {
                                        //   //console.log(key)
                                        return { group: key, info: e.Select('{"colName":$.colName,"baseGroup":$.baseGroup}').ToArray() };
                                    }, "$.toString()");

                                    //判断是否作为条件
                                    var isGroup = g.Count(function (arr) {
                                        var b = false;
                                        $.each(arr.info, function (i, obj) {
                                            if (obj.colName == col) {
                                                b = true;
                                            }
                                        });
                                        return b;
                                    }) > 0;
                                    // //console.log(col + ":" + isGroup);
                                    g.ForEach(function (arr) {
                                        var e = $.Enumerable.From(arr.info);
                                        if (e.Count(function (info) { return info.colName == col }) > 0) {
                                            e.ForEach(function (obj) {
                                                if (tableStep21.cell(row, obj.colName).data() != tableStep21.cell(row - 1, obj.colName).data()) {
                                                    //遍历所有条件
                                                    condition = true;
                                                }
                                                if (obj.baseGroup != 0) {//是否根级
                                                    nextGroup(obj)
                                                }
                                            });
                                        }
                                        if (!isGroup) {//不参数与条件筛选的也要和第一组一样
                                            e.ForEach(function (obj) {
                                                if (obj.baseGroup == 0) {
                                                    if (tableStep21.cell(row, obj.colName).data() != tableStep21.cell(row - 1, obj.colName).data()) {
                                                        condition = true;
                                                    }
                                                }

                                            });
                                        }
                                    });
                                    function nextGroup(obj) {//迭代下级
                                        g.Where(function (arr) {//查找上级
                                            return arr.group == obj.baseGroup;
                                        }).ForEach(function (arr2) {
                                            var e2 = $.Enumerable.From(arr2.info);
                                            e2.ForEach(function (obj2) {
                                                if (tableStep21.cell(row, obj2.colName).data() != tableStep21.cell(row - 1, obj2.colName).data()) {
                                                    condition = true;
                                                }
                                                nextGroup(obj2);
                                            });
                                        });

                                    }

                                }

                                var start = 0;
                                for (var i = row; i >= 0; i--) {
                                    var _starcol = $(tableStep21.cell(i, col).node()).attr("data-groupStart");
                                    if (_starcol > 0) {
                                        start = _starcol;
                                        break;
                                    }
                                }
                                //   var start =
                                if (condition) {
                                    ////console.log("row - groupIndex - 1")
                                    ////console.log(row - groupIndex - 1)
                                    $(td).attr("data-groupStart", row);// $("td:[data-groupStart]").attr("data-groupStart").attr();
                                    $(tableStep21.cell(start, col).node()).prop("rowspan", row - start);
                                    //  groupIndex = 0;//组index重新开始
                                } else {
                                    if (row == 0)//给第一行标记
                                    {
                                        $(td).attr("data-groupStart", row);
                                    } else {
                                        $(td).addClass("hide");
                                    }
                                    if (tableStep21.data().length - 1 == row)//最后一行
                                    {
                                        $(tableStep21.cell(start, col).node()).prop("rowspan", tableStep21.data().length - start);
                                    }
                                }

                                if (tableStep21.cell(row - 1, col).data() == cellData) {
                                    //   $(td).prop("rowspan", 2);
                                }

                            }
                            // ===============================================end分组分组分组分组分组分组分组分组分组分组分组end===============================================================================
                        },
                    ],
                    columns: [
                        { name: "SourceBillNo", title: "SourceBillNo", data: "SourceBillNo", visible: false },
                        {
                            data: null, Sortable: false, targets: 0,
                            title: "", className: "text-center",
                            render: function (data, type, row, meta) {
                                return '<input type="radio" name="checkItemstep21" class="checkItem" value="' + row.MaterialID + '" />';
                            },
                        },
                        { name: "MaterialID", title: "货号", data: "MaterialID", className: "text-center", defaultContent: "" },
                        { title: "尺码", "data": "SizeName", className: "text-center", defaultContent: "" },
                        { title: "单据数量", "data": "TotalQty", className: "text-center", defaultContent: "" }
                    ]
                };

                if (data == 1) {
                    opts.ajax = function (data, callback, settings) {
                        callback(
                            { "data": [] });
                    };
                } else {
                    var _url = "/api.ashx?c=PickingOperations&a=GetPMArrNoticeList";
                    opts.ajax = {
                        url: _url,
                        type: "POST",
                        dataSrc: function (json) {

                            if (json.Success == false) {
                                swal(json.Message, '', 'error');
                                return [];
                            } else {

                                return json.Data;
                            }
                        },
                        data: data
                    };
                }
                tableStep21 = $('#tableStep21').DataTable(opts);

            }
            function loadTableStep22() {
                tableStep22 = $('#tableStep22').DataTable({
                    ajax: {
                        url: "/api.ashx?c=OdsErpBasArea&a=GetAllOdsErpBasStockList",
                        type: "POST",
                        dataSrc: function (json) {
                            //  if(json.Data.length / 2)
                            if (json.Success == false) {
                                swal(json.Message, '', 'error');
                                return [];
                            } else {
                                json.data = json.Data;
                                var m = json.Data.length % 2 == 0;
                                var _leng = m ? json.Data.length : parseInt(json.Data.length / 2) + 1;

                                $.map(json.data, function (obj, i) {
                                    if (_leng > i) {
                                        if (_leng + i <= json.Data.length - 1) {
                                            obj.StockCode2 = json.Data[_leng + i].StockCode;
                                            obj.StockID2 = json.Data[_leng + i].StockID;
                                            obj.StockName2 = json.Data[_leng + i].StockName;
                                        } else {
                                            obj.StockCode2 = "";
                                            obj.StockID2 = "";
                                            obj.StockName2 = "";
                                        }
                                    }

                                });
                                json.data.splice(_leng, json.Data.length);
                                //console.log(json)
                                return json.data;
                            }
                        }
                    },
                    scrollY: tableStep22Height,
                    scrollCollapse: true,
                    retrieve: true,
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, ordering: false, lengthChange: false, processing: true,
                    drawCallback: function (setting) {
                        var api = this.api();
                        $(tableStep22.table().container()).find(".checkItem").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        //    $(tableStep21.table().container()).icheckAll({
                        //        checkObj: ".checkItem",//表格下面的选择控件对象 选择器
                        //        checkAllObj: "#checkAll",//全选 选择器
                        //        clickoutBoxCheck: false //点击行 不选中
                        //});
                    },

                    columns: [
                        {
                            data: "StockID", Sortable: false, targets: 0,
                            title: "", className: "text-center",
                            render: function (data, type, row, meta) {
                                return '<input type="checkbox" name="checkItemstep22" class="checkItem" data-text="' + row.StockName + '" value="' + row.StockID + '" />';
                            },
                        },
                        { title: "虚拟仓", data: "StockName", className: "text-center", width: "35%" },
                        {
                            data: "StockID2", Sortable: false, targets: 0,
                            title: "", className: "text-center",
                            render: function (data, type, row, meta) {
                                if (Y.checkNull(row.StockID2))
                                    return "";
                                else
                                    return '<input type="checkbox" name="checkItem" class="checkItem" data-text="' + row.StockName2 + '"  value="' + row.StockID2 + '" />';
                            },
                        },
                        { title: "虚拟仓", data: "StockName2", className: "text-center", width: "35%" },

                    ]
                });
            }
            function loadTableStep23(state, tabledata) {
                $("#tableStep23").show();
                isInsertDCVirtualStock = false;
                var opts = {

                    scrollY: tableStep23Height,//25是tfoot高
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, ordering: false, lengthChange: false, processing: true,
                    footerCallback: function (tfoot, data, start, end, display) {
                        //console.log("footerCallback")
                        var api = this.api(), data;
                        if (data.length > 0) {

                            var sizeCount = data[0].SizeCount;
                            var footTr = '<th colspan="2" class="text-center">可配数量</th><th hidden class="text-center"> </th>';
                            for (var i = 0; i <= sizeCount - 1; i++) {
                                footTr += '<th class="text-center"></th>';
                            }

                            $(tfoot).html(footTr);
                            calcAssignResult();
                        }
                    },

                    drawCallback: function () {
                        // tableStep23.cell(0,0).data(55).draw();
                        //console.log("drawCallback")
                        var keyChange = false;
                        //分配结果事件
                        tableStep23.$("input[name='step23InlineInput']").off("change");
                        tableStep23.$("input[name='step23InlineInput']").on("change", function () {
                            var e = e || event;
                            //  //console.log(e.type)

                            var v = $(this).val();
                            var td = $(this).parent("td");
                            var r = /^[0-9]*[0-9][0-9]*$/
                            if (!r.test(v)) {
                                swal("请输入正整数！");
                                tableStep23.draw();
                                return;
                            }
                            //  if (keyChange) { clearTimeout(keyChange); }
                            //  keyChange = setTimeout(function () {
                            tableStep23.cell(td).data(parseInt(v));
                            tableStep23.draw();
                            //  }, 1000);
                        });
                        $(".no-data-23").hide();

                    }
                };
                if (state != 1) {
                } else {
                    if (Y.checkNull(tabledata)) {
                        opts.ajax = function (data, callback, settings) {
                            //console.log("ajax")
                            callback(
                                { "data": [] });
                        };

                    } else {

                        createData(tabledata);
                    }
                }
                //console.log(tabledata);
                function createData(json) {
                    var tempList = { data: [] };
                    //var json2 = [{ StockID: "KM000083", StockName: "广东仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "M1", SizeName: "M", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM000083", StockName: "广东仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "1L", SizeName: "L", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM000083", StockName: "广东仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "XL1", SizeName: "XL", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM001121", StockName: "京北仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "M1", SizeName: "M", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM001121", StockName: "京北仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "L1", SizeName: "L", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM001121", StockName: "京北仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "X1L", SizeName: "XL", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM000876", StockName: "湖南仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "M1", SizeName: "M", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM000876", StockName: "湖南仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "L1", SizeName: "L", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // { StockID: "KM000876", StockName: "湖南仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "XL1", SizeName: "XL", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" }
                    //{ StockID: "KM000876", StockName: "湖南仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "XXL", SizeName: "XXL", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    //{ StockID: "KM000876", StockName: "湖南仓", SourceBillNo: "AN170313KMHK5171-001", SizeID: "XXXL", SizeName: "XXXL", TotalQty: 300, CompanyID: "KM", MaterialID: "1J1112002L0" },
                    // ];
                    //数据重组
                    opts.columns = [
                        { data: "StockName", Sortable: false, title: "虚拟仓", className: "text-center", width: 80 },
                        { data: "MaterialID", Sortable: false, title: "货号", className: "text-center" },
                    ];
                    //console.log("API3")
                    var _i = 0
                    var g = $.Enumerable.From(json).GroupBy("{CompanyID:$.CompanyID, StockID:$.StockID, SourceBillNo:$.SourceBillNo, StockName:$.StockName, MaterialID:$.MaterialID}", null,
                        function (key, e) {

                            var _templist = key;

                            e.ForEach(function (x) {
                                _templist[x.SizeName] = x.TotalQty;
                                _templist["SizeID" + x.SizeName] = x.SizeID;
                                if (_i == 0)
                                    opts.columns.push({
                                        data: x.SizeName, Sortable: false, title: x.SizeName, className: "text-center",
                                        render: function (data, type, row, meta) {
                                            //console.log("render")
                                            // //console.log(row[x.SizeName])
                                            return '<input type="number" name="step23InlineInput"  class="form-control input-sm inlineInput p-xxs" style="width:100%" data-size="' + x.SizeName + '" value="' + row[x.SizeName] + '" />';
                                        }
                                    });

                            });
                            _templist["SizeCount"] = e.Count();//尺码数
                            _i++;
                            tempList.data.push(_templist);
                            return key;
                        }, function (x) {
                            var _arr = [];
                            for (var i in x) {
                                _arr.push(x[i]);
                            }
                            return _arr.join("-");
                        }).ToArray();
                    //console.log("Enumerable")
                    //console.log(tempList)
                    opts.ajax = function (data, callback, settings) {
                        //console.log("ajax")
                        callback(tempList);
                    };
                }
                //要先清空表头，因为动态列不同时会出错
                if (tableStep23 && !Y.checkNull(tabledata)) {
                    $(tableStep23.table().header()).find("tr").html("");
                }
                tableStep23 = $('#tableStep23').DataTable(opts);
            }
            var clearTable23 = function () {
                $(tableStep23.table().footer()).find("tr th").remove();//特殊处理，由于datatables没有动态处理tfoot功能
                tableStep23.clear();
                tableStep23.destroy();

            }
            //选货号
            function loadTableStep31(data) {
                tableStep31 = $('#tableStep31').DataTable({
                    ajax: {
                        url: "/api.ashx?c=PickingOperations&a=GetDistribution",
                        type: "POST",
                        dataSrc: function (json) {
                            if (!json.Success) {
                                swal(json.Message, '', 'error');
                                return [];
                            } else {
                                return json.Data;
                            }
                        },
                        data: data
                    },
                    scrollY: tableStep31Height,
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, ordering: false, lengthChange: false, processing: true,
                    drawCallback: function (setting) {
                        var api = this.api();

                        $(tableStep31.table().container()).icheckAll({
                            checkObj: ".checkItem",//表格下面的选择控件对象 选择器
                            checkAllObj: ".checkAll",//全选 选择器
                            clickoutBoxCheck: false //点击行 是否选中
                        });
                        //选择 货号
                        api.$(".checkItem").on("ifChecked", function () {
                            var v = $(this).val()
                            if (!Y.checkNull(v)) {
                                var h = false;
                                $.each(MaterialIDList, function (i, o) {

                                    if (v == o.MaterialID) {
                                        h = true;
                                    }
                                });
                                if (!h) MaterialIDList.push({ "MaterialID": $(this).val() });
                            }

                        });
                        //删除
                        api.$(".checkItem").on("ifUnchecked", function () {
                            var v = $(this).val();
                            if (!Y.checkNull(v)) {
                                MaterialIDList = $.map(MaterialIDList, function (o) {
                                    return o.MaterialID == v ? null : o;
                                });
                            }
                        });
                        //合并后，把隐藏的checkbox 控件去掉，不去掉会有全选的影响
                        api.table().cells(function (idx, data, node) {
                            if (idx.column == 0) {
                                if ($(node).hasClass("hide")) {
                                    $(node).html("");
                                    return true;
                                }
                            }
                            return false;
                        });
                    },
                    createdRow: function (row, data, dataIndex) {
                        if ($(row).find("td:first[data-groupstart]").length > 0) {//给分组加粗线
                            $(row).addClass("groupRow");
                        }
                    },
                    columnDefs: [
                        {//==============================================分组分组分组分组分组分组分组分组分组分组分组=================================================================================
                            "targets": [0, 1, 2],//要合并的字段
                            "searchable": false,
                            createdCell: function (td, cellData, rowData, row, col) {
                                var table = tableStep31;//当前表格对象
                                var gcol = [{ colName: 1, group: 1, baseGroup: 0 }, { colName: 2, group: 1, baseGroup: 0 }];//要合并的组的条件，colName为对应的字段index，group：分组（1，2，3...） baseGroup:（父id）必须存在targets 中
                                $(table.cell(row, col).nodes()).addClass("groupbyColumn-" + row + " groupbyColumn-" + row + "-" + col);
                                var condition = false;
                                if (row != 0) {
                                    var g = $.Enumerable.From(gcol).GroupBy("$.group", "", function (key, e) {
                                        //   //console.log(key)
                                        return { group: key, info: e.Select('{"colName":$.colName,"baseGroup":$.baseGroup}').ToArray() };
                                    }, "$.toString()");

                                    //判断是否作为条件
                                    var isGroup = g.Count(function (arr) {
                                        var b = false;
                                        $.each(arr.info, function (i, obj) {
                                            if (obj.colName == col) {
                                                b = true;
                                            }
                                        });
                                        return b;
                                    }) > 0;
                                    // //console.log(col + ":" + isGroup);
                                    g.ForEach(function (arr) {
                                        var e = $.Enumerable.From(arr.info);
                                        if (e.Count(function (info) { return info.colName == col }) > 0) {
                                            e.ForEach(function (obj) {
                                                if (table.cell(row, obj.colName).data() != table.cell(row - 1, obj.colName).data()) {
                                                    //遍历所有条件
                                                    condition = true;
                                                }
                                                if (obj.baseGroup != 0) {//是否根级
                                                    nextGroup(obj)
                                                }
                                            });
                                        }
                                        if (!isGroup) {//不参数与条件筛选的也要和第一组一样
                                            e.ForEach(function (obj) {
                                                if (obj.baseGroup == 0) {
                                                    if (table.cell(row, obj.colName).data() != table.cell(row - 1, obj.colName).data()) {
                                                        condition = true;
                                                    }
                                                }

                                            });
                                        }
                                    });
                                    function nextGroup(obj) {//迭代下级
                                        g.Where(function (arr) {//查找上级
                                            return arr.group == obj.baseGroup;
                                        }).ForEach(function (arr2) {
                                            var e2 = $.Enumerable.From(arr2.info);
                                            e2.ForEach(function (obj2) {
                                                if (table.cell(row, obj2.colName).data() != table.cell(row - 1, obj2.colName).data()) {
                                                    condition = true;
                                                }
                                                nextGroup(obj2);
                                            });
                                        });

                                    }

                                }

                                var start = 0;
                                for (var i = row; i >= 0; i--) {

                                    var _starcol = $(table.cell(i, col).node()).attr("data-groupStart");

                                    if (_starcol > 0) {
                                        start = _starcol;
                                        break;
                                    }
                                }
                                //   var start =
                                if (condition) {
                                    ////console.log("row - groupIndex - 1")
                                    ////console.log(row - groupIndex - 1)
                                    $(td).attr("data-groupStart", row);// $("td:[data-groupStart]").attr("data-groupStart").attr();

                                    $(table.cell(start, col).node()).prop("rowspan", row - start);
                                    //  groupIndex = 0;//组index重新开始
                                } else {
                                    if (row == 0)//给第一行标记
                                    {
                                        $(td).attr("data-groupStart", row);
                                    } else {
                                        $(td).addClass("hide");
                                    }
                                    if (table.data().length - 1 == row)//最后一行
                                    {
                                        $(table.cell(start, col).node()).prop("rowspan", table.data().length - start);
                                    }
                                }



                                if (table.cell(row - 1, col).data() == cellData) {
                                    //   $(td).prop("rowspan", 2);
                                }

                            }
                            // ===============================================end分组分组分组分组分组分组分组分组分组分组分组end===============================================================================
                        },

                    ],
                    columns: [
                        {
                            data: null, Sortable: false, targets: 0, orderable: false, "name": "checkbox",
                            title: '<input type="checkbox" name="checkAllstep31" class="checkAll" value="all" />', className: "text-center",
                            render: function (data, type, row, meta) {
                                return '<input type="checkbox" name="checkItemstep31" class="checkItem" value="' + row.MaterialID + '" />';
                            },
                        },
                        { name: "MaterialID", title: "货号", data: "MaterialID", className: "text-center", defaultContent: "" },
                        { name: "MaterialShortName", title: "货号简称", data: "MaterialShortName", className: "text-center", defaultContent: "" },
                        { title: "尺码", data: "SizeName", "name": "SizeName", className: "text-center", defaultContent: "" },
                        { title: "库存数量", data: "TotalQty", "name": "TotalQty", className: "text-center", defaultContent: "" },
                        { title: "分配比例", data: "Percentage", "name": "Percentage", className: "text-center", defaultContent: "" },
                        { title: "分配数量", data: "AllottedNum", "name": "AllottedNum", className: "text-center", defaultContent: "" },
                        { title: "留库数量", data: "ReserveNum", "name": "ReserveNum", className: "text-center", defaultContent: "" },

                    ]
                });
            }

            // 店铺配货需求 操作数据 选中的店铺
            var step4Data = [];
            // 店铺配货需求 货号
            function loadTableStep41() {
                //console.log(MaterialIDList)
                //console.log(tableStep41Height)
                step4Data = [];
                tableStep41 = $('#tableStep41').DataTable({
                    data: MaterialIDList,
                    scrollY: tableStep41Height,
                    select: {
                        style: 'single'
                    },
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, ordering: false, lengthChange: false,
                    drawCallback: function (setting) {
                        var api = this.api();
                        api.off('select');
                        api.off('deselect');
                        api.on('select', function (e, dt, type, indexes) {
                            var rowData = dt.row(indexes).data();
                            if (tableStep42) tableStep42.destroy();
                             

                            //加载到表
                            loadTableStep42({ MaterialID: rowData.MaterialID, StockID: tableStep31.data()[0].StockID });
                            if (tableStep43) tableStep43.destroy();
                            loadTableStep43({ MaterialID: rowData.MaterialID });
                            if (tableStep44) {
                                tableStep44.destroy();
                                $('#tableStep44').empty();
                                tableStep44 = undefined;
                            }
                        });
                        api.on('deselect', function (e, dt, type, indexes) {
                            if (tableStep42) tableStep42.clear().draw();
                            if (tableStep43) tableStep43.clear().draw();
                            if (tableStep44) tableStep44.clear().draw();
                        });
                        //重置筛选
                        $("#filter-province").val("");
                        $("#filter-city").val("");
                        $("#isOrderFlag").iCheck("uncheck");
                    },
                    columns: [
                        { name: "MaterialID", title: "配货货号", data: "MaterialID", className: "text-center", defaultContent: "" }
                    ]

                });
            }

            // 店铺配货需求 供选择店铺
            function loadTableStep42(data) {
                var opts = {
                    select: {
                        style: 'multi'
                    },
                    scrollY: tableStep42Height,
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, ordering: false, lengthChange: false, processing: true,
                    drawCallback: function (setting) {
                        var api = this.api();
                    },

                    columns: [
                        { title: "店铺代码", data: "ShopCode", name: "ShopCode", className: "text-center", defaultContent: "", width: "60" },
                        { title: "店铺名称", data: "ShopName", "name": "ShopName", className: "text-center", defaultContent: "" },
                        { title: "企订量", data: "OrderFlag", "name": "OrderFlag", className: "text-center", defaultContent: "", width: "45" },
                        { title: "配货", data: "MoveFlag", "name": "MoveFlag", className: "text-center", defaultContent: "", width: "30" }
                    
                    ]
                };
                if (data == 1) {
                    opts.ajax = function (data, callback, settings) {
                        callback(
                            { "data": [] });
                    };
                } else {
                  
                    var linqEnum = $.Enumerable.From(step4Data).Where(function (x) { return x.MaterialID == data.MaterialID });

                    //判断step4Data是否已经存在 MaterialID对应的数据，是：不再请ajax
                    if (linqEnum.Count() > 0) {

                        opts.ajax = function (data, callback, settings) {

                            callback(
                                { data: step4GroupBy($.Enumerable.From(linqEnum.FirstOrDefault([]).Data).Where(function (x) { return !x.Selected; }).ToArray()) });
                        };
                    } else {
                        var _url = "/api.ashx?c=PickingOperations&a=GetShopDistributionList";
                        opts.ajax = {
                            url: _url,
                            type: "POST",
                            dataSrc: function (json) {

                                if (json.Success == false) {
                                    swal(json.Message, '', 'error');
                                    return [];
                                }
                                else {
                                    if (json.Data.length > 0) {

                                        if ($.Enumerable.From(step4Data).Count(function (x) { return x.MaterialID == data.MaterialID; }) == 0) {
                                            //把新post的数据 放到sep4Data，第二次不用再post
                                            step4Data.push({ MaterialID: data.MaterialID, Data: json.Data });
                                        }
                                    }

                                    return step4GroupBy(json.Data);
                                }

                            },
                            data: data
                        };
                    }
                }

                tableStep42 = $('#tableStep42').DataTable(opts);
            }
            // 店铺配货需求 已选择店铺
            function loadTableStep43(data) {
                var opts = {
                    scrollY: tableStep43Height,
                    select: {
                        style: 'single'
                    },
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, lengthChange: false, ordering: false,
                    drawCallback: function (setting) {
                        var api = this.api();

                        api.off('select');
                        api.off('deselect');
                        api.on('select', function (e, dt, type, indexes) {
                            //console.log(tableStep44)
                            if (tableStep44) {
                                tableStep44.destroy();
                            }
                            //console.log(234)
                            loadTableStep44();

                        });
                        api.on('deselect', function (e, dt, type, indexes) {
                            if (tableStep44) tableStep44.clear().draw();

                        });

                        //小屏 标题换行问题 溢出
                        var _h = $(tableStep43.table().container()).find(".dataTables_scrollHead").height();

                        if (_h > 40) {//如果大于40 说明表头换行了

                            $(tableStep43.table().container()).find(".dataTables_scrollBody").height($(tableStep43.table().container()).find(".dataTables_scrollBody").height() - _h + tableHeadHight);
                        }


                    },
                    columns: [
                        { title: "店铺代码", data: "ShopCode", name: "ShopCode", className: "text-center", defaultContent: "", width: "30%", orderable: false },
                        { title: "店铺名称", data: "ShopName", "name": "ShopName", className: "text-center", defaultContent: "", width: "50%", orderable: false },
                        { title: "配货需求量", data: "QtySum", "name": "QtySum", className: "text-center", defaultContent: "", width: "20%", orderable: false },
                        //{ title: "排序", data: "SortNum", "name": "SortNum", className: "text-center", defaultContent: "" }
                    ]
                };
                if (data == 1) {
                    opts.ajax = function (data, callback, settings) {
                        callback(
                            { "data": [] });
                    };
                } else {
                    var linqEnum = $.Enumerable.From(step4Data).Where(function (x) { return x.MaterialID == data.MaterialID });
                    //判断step4Data是否已经存在 MaterialID对应的数据，是：不再请ajax
                    if (linqEnum.Count() > 0) {
                        opts.ajax = function (data, callback, settings) {
                            callback(
                                { data: step4GroupBy($.Enumerable.From(linqEnum.FirstOrDefault([]).Data).Where(function (x) { return x.Selected; }).ToArray()) });
                        };
                    }
                }
                tableStep43 = $('#tableStep43').DataTable(opts);
            }
            //店铺配货需求 店铺需求数量
            function loadTableStep44() {
                var selectRowObj = tableStep43.row({ selected: true });
                var data = selectRowObj.data();
                var opts = {
                    data: [data],
                    scrollY: tableStep44Height,
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" }, scrollX: true, searching: false, paging: false, info: false, ordering: false, lengthChange: false,
                    drawCallback: function (setting) {
                        var api = this.api();
                    }
                }
                opts.columns = [
                    {
                        title: "尺码", data: null, name: "ShopCode", className: "text-center", cellType: "th", width: 50, defaultContent: "", render: function () {
                            return "数量";
                        }
                    }
                ];

                $.each(data.colName, function (i, col) {
                    opts.columns.push({ title: col, data: col, className: "text-center" });
                });
                //要先清空表头，因为动态列不同时会出错
                if (tableStep44) {
                    $(tableStep44.table().header()).find("tr").html("");
                }
                tableStep44 = $('#tableStep44').DataTable(opts);
            }
           
            var step4GroupBy = function (Data) {
           
                var tempList = [];
                var notSelected=$.Enumerable.From(Data).Count(function (x) { return !x.Selected; });// selected 为false的才执行 （注：selected为flase 说明是没选到已选择店铺 ，为true 就是已经选到已选择店铺，所以不需要执行）
                //.Where("!$.isFilter") 过虑
                var arr = $.Enumerable.From(Data).GroupBy("{  ShopName:$.ShopName, ShopCode:$.ShopCode, ShopID:$.ShopID,ProvinceName:$.ProvinceName,CityName:$.CityName,MaterialID:$.MaterialID,OrderFlag:$.OrderFlag,MoveFlag:$.MoveFlag}", null,
                    function (key, e) {
                        //console.log(key)
                        var _templist = key;
                        _templist["QtySum"] = e.Sum("$.Qty");
                        _templist["SortNum"] = 0;
                        _templist["Selected"] = false;
                        _templist["colName"] = [];
                        e.ForEach(function (x) {
                            _templist.colName.push(x.SizeName);
                            _templist[x.SizeName] = x.Qty;
                            _templist["SizeID" + x.SizeName] = x.SizeID;
                        });
                        _templist["SizeCount"] = e.Count();//尺码数
                        //console.log(_templist)
                        tempList.push(_templist);

                        return key;
                    }, function (x) {
                        var _arr = [];
                        for (var i in x) {
                            _arr.push(x[i]);
                        }
                        return _arr.join("-");
                    }).ToArray();
                //绑定到省市select  

                if (notSelected > 0) {//判断 selected 为false的才执行 （注：selected为flase 说明是没选到已选择店铺 ，为true 就是已经选到已选择店铺，所以不需要执行）
                    var _province = $("#filter-province").val();
                    var _city = $("#filter-city").val();
                    var _isOrderFlag = $("#isOrderFlag:checked").val();
                 
                    curShopProvAndCity = $.Enumerable.From(tempList).GroupBy("{ProvinceName:$.ProvinceName,CityName:$.CityName}", null, function (key, e) {
                        return key;
                    }, function (x) {
                        var _arr = [];
                        for (var i in x) {
                            _arr.push(x[i]);
                        }
                        return _arr.join("-");
                    }).ToArray();
                    bindShopCity(_city);
                    bindShopProv(_province);



                    //过虑
                    tempList=   $.Enumerable.From(tempList).Where(function (x) {
                        return (Y.checkNull(_province) || x.ProvinceName == _province) && (Y.checkNull(_city) || x.CityName == _city) && (Y.checkNull(_isOrderFlag) || x.OrderFlag == _isOrderFlag);
                    }).ToArray();
                
                  
                }
              
                return tempList;
            }
            //当前仓库省市 对象
            var curShopProvAndCity = [];
            //绑定 仓库 省
            var bindShopProv = function (_province) {
                $("#filter-province").html("<option value=''>全部</option>");
                $.Enumerable.From(curShopProvAndCity).GroupBy("{ProvinceName:$.ProvinceName}", null, function (key, e) {
                    return key;
                }, function (x) {
                    var _arr = [];
                    for (var i in x) {
                        _arr.push(x[i]);
                    }
                    return _arr.join("-");
                }).ForEach(function (x) {
                    $("#filter-province").append("<option value='" + x.ProvinceName + "'>" + x.ProvinceName + "</option>");
                });
                if (!Y.checkNull(_province)) {
                    $("#filter-province").val(_province);
                }
            }
            //绑定 仓库 市
            var bindShopCity = function (_city) {
                $("#filter-city").html("<option value=''>全部</option>");

                $.Enumerable.From(curShopProvAndCity).Where(function (x) {
                    //过虑没选中省份的市
                    if (!Y.checkNull($("#filter-province").val())) {
                        return $("#filter-province").val() == x.ProvinceName;
                    } else {
                        return true;
                    }
                }).ForEach(function (x) {
                   
                    $("#filter-city").append("<option value='" + x.CityName + "'>" + x.CityName + "</option>");
                        
                  
                });
              
                if (!Y.checkNull(_city)) {
                    $("#filter-city").val(_city);
                }
            }

            //过虑  刷新
            var filterTableStep42 = function () {
                if (typeof (tableStep42.ajax.url()) == "string") {
                    var selectRowsObj = tableStep41.row({ selected: true });
                    if (!Y.checkNull(selectRowsObj.data())) {
                        if (tableStep42) tableStep42.destroy();
                        loadTableStep42({ MaterialID: selectRowsObj.data().MaterialID, StockID: tableStep31.data()[0].StockID });
                    }
                } else {
                    tableStep42.ajax.reload();
                }
            };



            // 抢货作业  抢货
            function loadTableStep51(data) {
                var opts = {
                    scrollY: tableStep51Height,
                    language: { url: "../assets/js/plugins/jQuery-DataTables/i18n/Chinese.json" },
                    scrollX: true,
                    searching: false,
                    paging: true,
                    info: false,
                    ordering: false,
                    lengthChange: false,
                    processing: true,
                    //
                    pagingType: "simple_numbers",
                    scrollCollapse: false, //当显示更少的记录时，是否允许表格减少高度
                    serverSide: true, //是否开启服务器模式
                    pageLength: 50,
                    //
                    "initComplete": function(settings, json) {
                        $("#btn-search-shopReq").prop("disabled", false);
                        $('#tableStep51_paginate').parents('.row').find('.col-sm-5').hide();
                        $('#tableStep51_paginate').parent('div').css("z-index", 9999);

                        dataList = [];
                        //console.log("initComplete");
                    },
                    drawCallback: function(setting) {
                        var api = this.api();
                        //获取table和所有行
                        var tb = $(tableStep51.table().container());
                        var trArr = tb.find('tbody tr');
                        //先处理货号
                        var tdId1 = "";
                        var tdName1 = "";
                        var materialId1 = $(trArr).eq(0).find('td.MaterialID').text();
                        var name1 = $(trArr).eq(0).find('td.ShopName').text();
                        var span1 = 1;
                        var begin1 = 0;
                        for (var row = 1; row < trArr.length; row++) {
                            var tr = trArr[row];
                            tdId1 = $(tr).find('td').eq(2).text();
                            tdName1 = $(tr).find('td').eq(1).text();
                            if (tdId1 == materialId1 && name1 == tdName1) {
                                span1++;
                                $(trArr).eq(row).find('td').eq(2).remove();
                                $(trArr).eq(row).find('td').eq(1).remove();
                                $(trArr).eq(row).find('td').eq(0).remove();


                            } else {
                                $(trArr).eq(begin1).find('td').eq(2).prop('rowspan', span1);
                                $(trArr).eq(begin1).find('td').eq(1).prop('rowspan', span1);
                                $(trArr).eq(begin1).find('td').eq(0).prop('rowspan', span1);
                                materialId1 = tdId1;
                                name1 = tdName1;
                                span1 = 1;
                                begin1 = row;
                            }
                        }
                        //处理最后一行货号
                        tdId1 = $(trArr).eq(trArr.length - 1).find('td.MaterialID').text();
                        tdName1 = $(tr).find('td').eq(1).text();
                        if (tdId1 == materialId1 && name1 == tdName1) {
                            span1++;
                            $(trArr).eq(trArr.length - 1).find('td').eq(2).remove();
                            $(trArr).eq(trArr.length - 1).find('td').eq(1).remove();
                            $(trArr).eq(trArr.length - 1).find('td').eq(0).remove();
                        } else {
                            $(trArr).eq(begin1).find('td').eq(2).prop('rowspan', span1);
                            $(trArr).eq(begin1).find('td').eq(1).prop('rowspan', span1);
                            $(trArr).eq(begin1).find('td').eq(0).prop('rowspan', span1);
                            materialId1 = tdId1;
                            span1 = 1;
                            begin1 = trArr.length - 1;
                        }
                        
                        //
                        $(tableStep51.table().container()).icheckAll({
                            checkObj: ".checkItem", //表格下面的选择控件对象 选择器
                            checkAllObj: ".checkAll", //全选 选择器
                            clickoutBoxCheck: false //点击行 是否选中
                        });
                        //处理红色
                        //var trs = $('.IsRedText').parents('tr');
                        //trs.each(function() {
                        //    var shop = $(this).find('.ShopName').text();
                        //    $('td:textEquals(' + shop + ')').parents('tr').find('.SizeName').addClass('RedText');
                        //});
                        //

                        //默认全选
                        $('#tableStep51').iCheck('check');
                        //已有的去掉勾
                        for (var i = 0; i < dataList.length; i++) {
                            //复选框（店铺ID）
                            var c = $('.checkItem:visible[value=' + dataList[i].ShopID + ']');
                            if (c.length > 0) {
                                var m = c.parents('tr').find('.MaterialID').text();
                                if (m == dataList[i].MaterialID) {
                                    c.iCheck('uncheck');
                                }
                            }
                        }

                        $('input').on('ifChecked', function (event) {
                            var shopId = $(this).val();
                            var materialID = $(this).parents('tr').find('.MaterialID').text();

                            //console.log(shopId + "-" + materialID);
                            dataList.pop({ ShopID: shopId, MaterialID: materialID });
                        });
                        $('input').on('ifUnchecked', function (event) {
                            var shopId = $(this).val();
                            var materialID = $(this).parents('tr').find('.MaterialID').text();

                            //console.log(shopId + "-" + materialID);
                            if (shopId != "all") {
                                dataList.push({ ShopID: shopId, MaterialID: materialID });
                            }
                        });



                        //合并后，把隐藏的checkbox 控件去掉，不去掉会有全选的影响
                        api.table().cells(function(idx, data, node) {
                            if (idx.column == 0) {
                                if ($(node).hasClass("hide")) {
                                    $(node).html("");
                                    return true;
                                }
                            }
                            return false;
                        });


                    },
                    columns: [
                        {
                            data: null, Sortable: false, targets: 0, orderable: false, "name": "checkbox",
                            title: '<input type="checkbox" name="checkAllstep51" class="checkAll" value="all" />', className: "text-center",
                            render: function (data, type, row, meta) {
                                return '<input type="checkbox" name="checkItemstep51" class="checkItem" value="' + row.ShopID + '" />';
                            },
                        },
                        { name: "ShopName", title: "店铺", data: "ShopName", className: "text-center ShopName", defaultContent: "" },
                        { name: "MaterialID", title: "货号", data: "MaterialID", className: "text-center MaterialID", defaultContent: "" },
                        //{ name: "MaterialShortName", title: "货号简称", data: "MaterialShortName", className: "text-center", defaultContent: "" },
                        {
                            title: "尺码", data: "SizeName", "name": "SizeName", className: "text-center SizeName", defaultContent: "",
                            render: function (data, type, row, meta) {
                                var okClass = (row.SizeCoreFlag == 1 && row.ActualQty == 1) ? " RedText" : "";
                                return '<div class="text-center' + okClass + '">' + row.SizeName + '</div>';
                            }
                        },
                        { title: "数量", data: "Qty", "name": "Qty", className: "text-center", defaultContent: "" },
                        { title: "抢货结果", data: "ActualQty", "name": "ActualQty", className: "text-center", defaultContent: "" }
                    ]
                };

                opts.ajax = function (datas, callback, settings) {
                    var param = {
                        "Size": datas.length,
                        "Page": (datas.start / datas.length) + 1,
                        "TaskBillNo": data.TaskBillNo,
                        "OutStockID": data.OutStockID,
                        "Type": data.Type
                    };
                    var url = "/api.ashx?c=PickingOperations&a=GetShopReqDetail" + "&t=" + Math.random();
                    $.ajax({
                        type: "post",
                        url: url,
                        data: param,
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            //console.log(result.Data);
                            if (result.Data == "") {
                                returnData.draw = datas.draw;
                                returnData.recordsTotal = 0;
                                returnData.recordsFiltered = 0;
                                returnData.data = [];
                            }
                            else {
                                returnData.draw = datas.draw;
                                returnData.recordsTotal = result.Data.RecordCount;
                                returnData.recordsFiltered = result.Data.RecordCount;
                                returnData.data = result.Data.Items;
                            }

                            callback(returnData);
                          
                        }
                    });
                };

                tableStep51 = $('#tableStep51').DataTable(opts);

            }
            // tableStep51

            //#endregion 

            //计算 数据操作


            //计算 分配结果
            var calcAssignResult = function () {

                if (tableStep23.data()) {
                    var _material = tableStep21.data().filter(function (obj, ii) {
                        return obj.MaterialID == tableStep23.row(0).data().MaterialID; //找对应货号
                    });
                    for (var i = tableStep23.columns().data().length - 1; i >= 0; i--)//循环列
                    {

                        if ($.isNumeric(tableStep23.cell(0, i).data()))//判断是否数字 排除列 虚拟仓和货号，留下尺码
                        {
                            var qty = 0;
                            _material.filter(function (obj, ii) {
                                return obj.SizeName == tableStep23.column(i).dataSrc();
                            }).each(function (o) {//其实原理上到这里只有一条数据
                                //console.log(o);
                                qty = o.TotalQty;
                            });
                            var sum = tableStep23.column(i).data().reduce(function (a, b) {
                                return a + b;
                            });
                            //console.log(tableStep23.column(i).footer())
                            var r = qty - sum;
                            var fth = $(tableStep23.table().footer()).find("tr th").eq(i);
                            fth.html(r);
                            if (r != 0) {
                                fth.addClass("text-danger");
                            } else {
                                fth.removeClass("text-danger");
                            }
                        }

                    }
                }

            }
            //计算 分配比例结果  选货号
            var calcAllotted = function (_allottedPercent) {
                //tableStep31.rows().each(function (row,i) {
                //    row
                //});
                //tableStep31.column("TotalQty:name").index()
                //var cells = tableStep31.cells("", "Percentage:name");
                //cells.nodes().each(function (td) {
                //    tableStep31.cell(td).data(_allottedPercent);
                //});
                // TotalQty
                tableStep31.rows().nodes().each(function (tr, i) {
                    tableStep31.cell(tr, "Percentage:name").data(numeral(_allottedPercent).divide(100).format("0.00"));
                    var totalQty = tableStep31.cell(tr, "TotalQty:name").data();
                    var allottedNum = numeral(_allottedPercent).divide(100).multiply(totalQty);
                    tableStep31.cell(tr, "AllottedNum:name").data(allottedNum.format("0"));
                    tableStep31.cell(tr, "ReserveNum:name").data(numeral(totalQty).subtract(allottedNum.format("0")).format("0"));

                });

            }
            //操作 已选择店铺 和 供选择店铺  add：已选择店铺 设置成Selected=true  del: 设置成Selected=false
            var dataProcessStep4 = function (selectRowsObj, oper) {
                if (oper == "add") {
                    selectRowsObj.data().each(function (row, index) {
                        $.Enumerable.From(step4Data).Where(function (x) { return x.MaterialID == row.MaterialID; })
                            .ForEach(function (x) {
                                $.Enumerable.From(x.Data).Where(function (x) { return x.ShopID == row.ShopID; }).ForEach(function (x) { x.Selected = true });
                            });
                    });
                    //console.log(step4Data);
                }
                else if (oper == "del") {
                    selectRowsObj.data().each(function (row, index) {
                        $.Enumerable.From(step4Data).Where(function (x) { return x.MaterialID == row.MaterialID; })
                            .ForEach(function (x) {
                                $.Enumerable.From(x.Data).Where(function (x) { return x.ShopID == row.ShopID; }).ForEach(function (x) { x.Selected = false });
                            });
                    });
                    //console.log(step4Data);
                }

            }


        });
    </script>

</asp:Content>

